package com.tang.common.component;

import org.redisson.api.RBucket;
import org.redisson.api.RSemaphore;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class RedisCache {

    @Resource
    private RedissonClient redissonClient;


    public <T> void set(String key, T data) {
        RBucket<T> bucket = redissonClient.getBucket(key);
        bucket.set(data);
    }

    public <T> void set(String key, T data, long time, TimeUnit timeUnit) {
        RBucket<T> bucket = redissonClient.getBucket(key);
        bucket.set(data, time, timeUnit);
    }


    public <T> T get(String key) {
        RBucket<T> bucket = redissonClient.getBucket(key);
        return bucket.get();
    }

    public <T> Boolean isExists(String key) {
        RBucket<T> bucket = redissonClient.getBucket(key);
        return bucket.isExists();
    }

    public <T> Boolean delete(String key) {
        RBucket<T> bucket = redissonClient.getBucket(key);
        return bucket.delete();
    }
}
